package seekting.demo2017.activity;

import android.app.Activity;
import android.os.Bundle;
import android.os.Looper;
import android.util.Log;

import rx.Observable;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import seekting.demo2017.AppEnv;

/**
 * Created by seekting on 17-5-18.
 */

public class RxJavaActivity extends Activity {

    public static final boolean DEBUG = AppEnv.bAppdebug;
    public static final String TAG = RxJavaActivity.class.getSimpleName();
    private Observable.OnSubscribe<String> mOnSubscribe;
    private Observable<String> mObservable;
    private Subscriber mSubscriber;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (DEBUG) {
            Log.d(TAG, "onCreate.");
        }


        Observable.OnSubscribe<Boolean> j = new Observable.OnSubscribe<Boolean>() {
            @Override
            public void call(Subscriber<? super Boolean> subscriber) {
                Log.d("seekting", "EditActivity.call()" + Thread.currentThread().getName());
                Log.d("seekting", "EditActivity.call()" + (Looper.myLooper() == Looper.getMainLooper()));
                subscriber.onNext(true);
            }
        };
        Observable observable = Observable.create(j);
        observable = observable.subscribeOn(Schedulers.io());
        observable = observable.observeOn(AndroidSchedulers.mainThread());
        observable.subscribe(new Subscriber<Boolean>() {

            @Override
            public void onStart() {
            }

            @Override
            public void onCompleted() {
            }

            @Override
            public void onError(Throwable throwable) {
            }

            @Override
            public void onNext(Boolean r) {
                Log.d("seekting", "EditActivity.call()" + (Looper.myLooper() == Looper.getMainLooper()));

            }
        });


    }


}